<?php
    require "sql.php";
    $data=array(
        array('code'=>1),
        array('code'=>2),
        array('code'=>3)
    );
    $expire =time() +60*60;
    $user['text'] = $_POST['text'];
    $user['password'] = md5($_POST['password']);
    $str1="select * from user where email = '".$user['text']."' or name = '".$user['text']."'"; 
    $result = $conn->query($str1);
    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            if($user['password']==$row['passwords']){
                setcookie("username", $row['name'], $expire);
                setcookie("email", $row['email'], $expire);
                $str3="insert into log(log_name,log_time,log_kind) values('".$row['name']."','".date('Y-m-d H:i:s')."','账户登录')";
                $conn->query($str3);
                echo json_encode($data[0]);
            }else{
                echo json_encode($data[1]);
            }
        }
    } else {
        echo json_encode($data[2]);
    }
    $conn->close();
